package org.lookahead.parent.apidoc.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.lookahead.parent.apidoc.enums.QAbility.*;
import static org.lookahead.parent.apidoc.enums.QExercise.*;


/**
 * 题型枚举类
 * @author Lookahead
 * @since 2021-07-02
 */
@Getter
@AllArgsConstructor
public enum QTypeEnum {

    // 1-配音类
    DUBBING_1("边看动画片，边跟读", 1, AnswerTime.TIME_SECOND_60.val, "Watch and dub. 动画片配音"),
    DUBBING_2("边听儿歌，边跟读", 2, AnswerTime.TIME_SECOND_60.val, "Sing and dub. 歌曲配音"),
    DUBBING_3("角色扮演", 15, AnswerTime.TIME_SECOND_60.val, "Role play. 角色扮演"),
    DUBBING_4("看动画片", 27, AnswerTime.TIME_SECOND_60.val, "Watch the cartoon. 观看动画片"),
    DUBBING_5("角色扮演音频版", 28, AnswerTime.TIME_SECOND_DEFAULT.val, "Role play. 角色扮演"),
    // 2-选择类
    CHOICE_1("听音选图", 3, AnswerTime.TIME_SECOND_6.val, "Listen and choose. 听音选图"),
    CHOICE_2("听音选词", 5, AnswerTime.TIME_SECOND_6.val, "Listen and choose. 听音选词"),
    CHOICE_3("看图判断对错", 7, AnswerTime.TIME_SECOND_8.val, "Read and judge. 判断正误"),
    CHOICE_4("看词选图", 8, AnswerTime.TIME_SECOND_6.val, "Read and choose. 看词选图"),
    CHOICE_5("看图选词", 9, AnswerTime.TIME_SECOND_6.val, "Look, read and choose. 看图选词"),
    CHOICE_6("单选或复选题", 21, AnswerTime.TIME_SECOND_8.val, "Read and choose. 单项选择"),
    CHOICE_7("听音看句子选图", 29, AnswerTime.TIME_SECOND_DEFAULT.val, ""),
    // 3-语音类
    AUDIO_1("单词跟读", 6, AnswerTime.TIME_SECOND_5.val, "Listen and repeat. 单词跟读"),
    AUDIO_2("看单词图片说单词", 14, AnswerTime.TIME_SECOND_8.val, "Look and read. 看图读词"),
    AUDIO_3("听问题回答", 16, AnswerTime.TIME_SECOND_8.val, "Listen and answer. 回答问题"),
    AUDIO_4("句子跟读", 17, AnswerTime.TIME_SECOND_8.val, "Listen and repeat. 句子跟读"),
    AUDIO_5("朗读句子或短文", 23, AnswerTime.TIME_SECOND_20.val, "Listen and repeat. 短文朗读"),
    // 4-连线类
    MATCHING_1("图词连线", 11, AnswerTime.TIME_SECOND_12.val, "Read and match. 图词配对"),
    MATCHING_2("词词连线", 12, AnswerTime.TIME_SECOND_12.val, "Read and match. 单词配对"),
    MATCHING_3("图图连线", 13, AnswerTime.TIME_SECOND_12.val, "Read and match. 图片配对"),
    MATCHING_4("图文连线", 25, AnswerTime.TIME_SECOND_12.val, "Read and match. 图文配对"),
    // 5-填空类
    COMPLETION_1("听音选字母补全单词", 4, AnswerTime.TIME_SECOND_8.val, "Listen and choose. 听音补全单词"),
    COMPLETION_2("补全句子或对话", 19, AnswerTime.TIME_SECOND_15.val, "Read and choose. 补全句子"),
    COMPLETION_4("连词组句", 30, AnswerTime.TIME_SECOND_10.val, "Write in order.连词成句"),
    // 6-分组类
    GROUP_1("单词分类", 10, AnswerTime.TIME_SECOND_12.val, "Read and classify. 单词分类"),
    //	V("问答题", 22),
    // 7-排序类
    SORT_1("听句子看图排序", 20, AnswerTime.TIME_SECOND_15.val, "Listen and unscramble. 听句子排序"),
    SORT_2("听音频给图片排序", 26, AnswerTime.TIME_SECOND_10.val, "Listen and unscramble. 听音排序"),
    // 8-拼写类
    SPELL_1("句子拼写", 31, AnswerTime.TIME_SECOND_15.val, "Read and write. 补全对话"),
    SPELL_2("单词拼写", 32, AnswerTime.TIME_SECOND_10.val, "Look and write. 单词拼写"),
    // 9-阅读类
    READ_1("完形填空", 24, AnswerTime.TIME_SECOND_180.val, "Read and choose. 完形填空"),
    READ_2("阅读理解", 33, AnswerTime.TIME_SECOND_180.val, "Read and choose. 阅读理解"),
    DEFAULT("其他", 99, AnswerTime.TIME_SECOND_DEFAULT.val, ""),
    ;

    final String name;
    final int value;
    final int answerTime;
    final String memo;

    static final Map<Integer, QTypeEnum> qTypeEnumMap = new HashMap<>();

    static {
        for (QTypeEnum qTypeEnum : QTypeEnum.values()) {
            qTypeEnumMap.put(qTypeEnum.getValue(), qTypeEnum);
        }
    }

    public static QTypeEnum getEnum(Integer qType) {
        return qTypeEnumMap.getOrDefault(qType, DEFAULT);
    }

    /**
     * 是否是语音题
     *
     * @param value 题型code
     * @return true 是语音题  false不是语音题
     */
    public static Boolean isVoice(Integer value) {
        switch (getEnum(value)) {
            case DUBBING_1:
            case DUBBING_2:
            case DUBBING_3:
//            case DUBBING_4:   // 看动画片没有语音评分
            case DUBBING_5:
            case AUDIO_1:
            case AUDIO_2:
            case AUDIO_3:
            case AUDIO_4:
            case AUDIO_5:
                return true;
            default:
                return false;
        }
    }

    /**
     * 判断是否是配音题
     *
     * @param questionTypeId 题目类型
     * @return boolean
     */
    public static Boolean isDubbing(Integer questionTypeId) {
        switch (getEnum(questionTypeId)) {
            case DUBBING_1:
            case DUBBING_2:
            case DUBBING_3:
                return true;
            default:
                return false;
        }
    }

    /**
     * 判断是否是高级别题型
     *
     * @param questionTypeId 题目类型
     * @return boolean
     */
    public static Boolean isAdvance(Integer questionTypeId) {
        switch (getEnum(questionTypeId)) {
            case SPELL_1:
            case SPELL_2:
            case READ_1:
            case READ_2:
            case COMPLETION_4:
                return true;
            default:
                return false;
        }
    }

    /**
     * 获取名称
     *
     * @param value 题型code
     * @return 题型名称
     */
    public static String getName(Integer value) {
        QTypeEnum qTypeEnum = qTypeEnumMap.getOrDefault(value, DEFAULT);
        return qTypeEnum.getName();
    }


    /**
     * 获取练习内容
     *
     * @param value 题型code
     * @return 练习内容code
     */
    public static List<Integer> getQExercise(Integer value) {
        List<Integer> objects = new ArrayList<>();
        if (value.equals(AUDIO_1.value)
            || value.equals(CHOICE_1.value)
            || value.equals(CHOICE_2.value)
            || value.equals(CHOICE_4.value)
            || value.equals(CHOICE_5.value)
            || value.equals(GROUP_1.value)
            || value.equals(MATCHING_1.value)
            || value.equals(MATCHING_2.value)
            || value.equals(MATCHING_3.value)
            || value.equals(COMPLETION_1.value)
            || value.equals(SPELL_2.value)) {
            //词汇
            objects.add(EXERCISE_WORDS.value);
        }
        if (value.equals(DUBBING_1.value)
            || value.equals(DUBBING_2.value)
            || value.equals(DUBBING_3.value)
            || value.equals(AUDIO_4.value)
            || value.equals(CHOICE_6.value)
            || value.equals(MATCHING_4.value)
            || value.equals(COMPLETION_2.value)
            || value.equals(COMPLETION_4.value)
            || value.equals(SORT_1.value)
            || value.equals(SORT_2.value)
            || value.equals(AUDIO_3.value)
            || value.equals(CHOICE_3.value)
            || value.equals(SPELL_1.value)) {
            //句型
            objects.add(EXERCISE_SENTENCE.value);
        }
        if (value.equals(DUBBING_1.value)
            || value.equals(DUBBING_4.value)
            || value.equals(DUBBING_2.value)
            || value.equals(DUBBING_3.value)) {
            //对话
            objects.add(EXERCISE_DIALOGUE.value);
        }
        if (value.equals(DUBBING_1.value)
            || value.equals(DUBBING_4.value)
            || value.equals(DUBBING_2.value)
            || value.equals(DUBBING_3.value)
            || value.equals(AUDIO_5.value)
            || value.equals(CHOICE_6.value)
            || value.equals(COMPLETION_2.value)
            || value.equals(SORT_2.value)
            || value.equals(READ_1.value)
            || value.equals(CHOICE_3.value)
            || value.equals(READ_2.value)) {
            //语篇
            objects.add(EXERCISE_DISCOURSE.value);
        }
        if (value.equals(DUBBING_1.value)
            || value.equals(DUBBING_2.value)
            || value.equals(DUBBING_3.value)
            || value.equals(AUDIO_1.value)
            || value.equals(AUDIO_4.value)
            || value.equals(AUDIO_5.value)) {
            //语音
            objects.add(EXERCISE_VOICE.value);
        }
        return objects;
    }

    /**
     * 获取练习能力
     *
     * @param value 题型code
     * @return 题型能力code
     */
    public static List<Integer> getQAbility(Integer value) {
        List<Integer> objects = new ArrayList<>();
        if (value.equals(DUBBING_4.value)
            || value.equals(DUBBING_1.value)
            || value.equals(DUBBING_2.value)
            || value.equals(DUBBING_3.value)
            || value.equals(CHOICE_1.value)
            || value.equals(CHOICE_2.value)
            || value.equals(COMPLETION_1.value)
            || value.equals(SORT_1.value)
            || value.equals(AUDIO_3.value)
            || value.equals(SORT_2.value)) {
            //听
            objects.add(ABILITY_HEAR.value);
        }
        if (value.equals(AUDIO_3.value)) {
            //说
            objects.add(ABILITY_SAY.value);
        }
        if (value.equals(DUBBING_1.value)
                || value.equals(DUBBING_2.value)
                || value.equals(DUBBING_3.value)
                || value.equals(AUDIO_1.value)
                || value.equals(AUDIO_4.value)
                || value.equals(AUDIO_5.value)
                || value.equals(CHOICE_2.value)
                || value.equals(CHOICE_4.value)
                || value.equals(CHOICE_5.value)
                || value.equals(CHOICE_6.value)
                || value.equals(GROUP_1.value)
                || value.equals(MATCHING_1.value)
                || value.equals(MATCHING_2.value)
                || value.equals(MATCHING_4.value)
                || value.equals(COMPLETION_1.value)
                || value.equals(COMPLETION_2.value)
                || value.equals(COMPLETION_4.value)
                || value.equals(SORT_1.value)
                || value.equals(SPELL_1.value)
                || value.equals(SPELL_2.value)
                || value.equals(READ_1.value)
                || value.equals(AUDIO_3.value)
                || value.equals(CHOICE_3.value)
                || value.equals(READ_2.value)) {
            //读
            objects.add(ABILITY_READ.value);
        }
        if (value.equals(SPELL_1.value)
            || value.equals(SPELL_2.value)) {
            //写
            objects.add(ABILITY_WRITE.value);
        }
        if (value.equals(DUBBING_4.value)
            || value.equals(CHOICE_1.value)
            || value.equals(CHOICE_4.value)
            || value.equals(CHOICE_5.value)
            || value.equals(CHOICE_6.value)
            || value.equals(GROUP_1.value)
            || value.equals(MATCHING_1.value)
            || value.equals(MATCHING_2.value)
            || value.equals(MATCHING_3.value)
            || value.equals(MATCHING_4.value)
            || value.equals(COMPLETION_2.value)
            || value.equals(SORT_2.value)
            || value.equals(AUDIO_3.value)
            || value.equals(CHOICE_3.value)
            || value.equals(SPELL_1.value)
            || value.equals(SPELL_2.value)) {
            //看
            objects.add(ABILITY_SEE.value);
        }
        return objects;
    }


    public static Integer getAnswerTime(Integer value) {
        QTypeEnum qTypeEnum = qTypeEnumMap.getOrDefault(value, DEFAULT);
        return qTypeEnum.getAnswerTime();
    }

    public static Boolean isDubbing(String questionCodeName) {
        if (QTypeEnum.DUBBING_1.getName().equals(questionCodeName)) {
            return true;
        } else if (QTypeEnum.DUBBING_2.getName().equals(questionCodeName)) {
            return true;
        } else if (QTypeEnum.DUBBING_3.getName().equals(questionCodeName)) {
            return true;
        } else if (QTypeEnum.DUBBING_4.getName().equals(questionCodeName)) {
            return true;
        } else if (QTypeEnum.DUBBING_5.getName().equals(questionCodeName)) {
            return true;
        } else {
            return false;
        }
    }

    public static Boolean voiceScoreIsCorrect(Integer score) {
        return score != null && score >= 60;
    }


/*
1	边看动画片，边跟读
2	边看儿歌，边跟读
3	听音选图
4	听音选字母补全单词
5	听音选词
6	单词跟读
7	认读句子，看图判断对错
8	看词选图
9	看图选词
10	单词分类
11	图词连线
12	词词连线
13	字母连线
14	看单词图片说单词（语音词）
15	role play
16	听问题回答
17	句子跟读
18	认读句子，看图判断对错（语法点）
19	选择短语或词汇，补全句子或对话
20	听句子看图排序
21	对话-单项选择
22	看图、听问句，根据课文回答问题
23	朗读句子、短文
24	完形填空
25	图文连线
26	听音频给图片排序
27	看动画片
28	Role Play音频版
29	听音看句子选图
30	连词组句
31  对话拼写
32  单词拼写
33  阅读理解
*/

}
